//
//  LMRTabsView.m
//  EditTabDemo
//
//  Created by lhy on 2021/2/26.
//  Copyright © 2021 lhy. All rights reserved.
//

#import "LMRTabsView.h"

@interface LMRTabsView ()

@end

@implementation LMRTabsView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.cornerRadius = 2;
        self.layer.borderWidth = 1;
        self.layer.borderColor = UIColor.lightGrayColor.CGColor;
        self.layer.masksToBounds = YES;
        
        
//        self.backgroundColor = UIColor.redColor;
        if (CGRectEqualToRect(frame, CGRectZero)) {
            self.frame = CGRectMake(0, 0, 100, 44);
        }
        UIButton *selectBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, frame.size.width - 20, frame.size.height)];
        self.selectBtn = selectBtn;
        [selectBtn setTitle:@"文件A" forState:UIControlStateNormal];
        selectBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [selectBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
        [selectBtn addTarget:self action:@selector(tabSelected:) forControlEvents:UIControlEventTouchUpInside];
        [selectBtn setBackgroundColor:UIColor.clearColor];
        [self addSubview:selectBtn];
        
        UIButton *deleteBtn = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width - 20, 0, 20, 44)];
        self.deleteBtn = deleteBtn;
        deleteBtn.hidden = YES;
        [deleteBtn setTitle:@"x" forState:UIControlStateNormal];
        [deleteBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
        [deleteBtn addTarget:self action:@selector(tabDelete:) forControlEvents:UIControlEventTouchUpInside];
        [deleteBtn setBackgroundColor:UIColor.clearColor];
        [self addSubview:deleteBtn];
    }
    return self;
}

- (void)tabDelete:(UIButton *)sender {
    if (self.tabDeleteBlock) {
        self.tabDeleteBlock(self.tag);
    }
}

- (void)tabSelected:(UIButton *)sender {
    if (self.tabSelectedBlock) {
        self.tabSelectedBlock(self.tag);
    }
}

- (void)setBtnTitle:(NSString *)btnTitle {
    _btnTitle = btnTitle;
    [self.selectBtn setTitle:_btnTitle forState:UIControlStateNormal];
}

//- (void)setBackgroundColor:(UIColor *)backgroundColor {
//    _backgroundColor = backgroundColor;
//    self.selectBtn.backgroundColor = _backgroundColor;
//    self.deleteBtn.backgroundColor = _backgroundColor;
//}

@end
